package first

import "gitee.com/themoonstone/toOffer/first/original"

/*
	输入两个链表，找出它们的第一个公共节点。

	如下面的两个链表：

	https://leetcode-cn.com/problems/liang-ge-lian-biao-de-di-yi-ge-gong-gong-jie-dian-lcof/
*/
func getIntersectionNode(headA, headB *original.ListNode) *original.ListNode {
	h1, h2 := headA, headB
	for h1 != h2 {
		if h1 == nil {
			h1 = headB
		} else {
			h1 = h1.Next
		}
		if h2 == nil {
			h2 = headA
		} else {
			h2 = h2.Next
		}

	}

	return h1
}
